﻿<?php
class IndexActionController extends ActionController {

    public function run() {
        
        $userMapper = new UserMapper();
        $articleMapper = new ArticleMapper();
        
        if (isset($this->params['logout'])) {
            $userMapper->logOut($this->user);
        }
        
        if (isset($this->params['del'])) {
            $articleMapper->dao->delEntry($this->params['id']);
            $commentMapper = new CommentMapper();
            $commentMapper->dao->delEntry($this->params['id'], 'artID');
        }
        
        if (isset($this->params['tag'])){
            $arts = $articleMapper->getArticlesByTags($this->params['tag']);
        } elseif (isset($this->params['authorID'])) {
            $arts = $articleMapper->getArticles('userID', $this->params['authorID']);
        } else {
            $arts = $articleMapper->getArticles();
        }
        
        $userMapper->getFullUserName($arts);
        $userMapper->getKarma($arts);
        $commentMapper = new CommentMapper();
        $commentMapper->getCountCommentsForArticles($arts);
        
        $this->view->articles = $arts;
        $this->view->user = $this->user;
        
        $this->view->setRenderTemplate('index.phtml');
    }
}

?>